//
//  GoodsList_ViewController.m
//  CarNetwork_logistics
//
//  Created by 高启 on 15/11/13.
//  Copyright © 2015年 turingEdu. All rights reserved.
//

#import "GoodsList_ViewController.h"
#import "EreaListModel.h"
@interface GoodsList_ViewController ()

@end

@implementation GoodsList_ViewController
{
    NSMutableArray    *currentData;
    UITableView       *myTableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navtitle.text = @"货品类型";
    [self createTableView];
    [self dataManager];
    
    // Do any additional setup after loading the view.
}
/**
 *  数据处理
 */
- (void)dataManager
{
    EreaListModel  *ereaModel = [EreaListModel sharedManager];
    
    currentData = [ereaModel getGoodsList];
    [myTableView reloadData];
   
}


- (void)createTableView
{
    myTableView = [[UITableView alloc]init];
    [myTableView setFrame:CGRectMake(0, 1, kUIScreenWidth, kUIScreenHeight-kStateNavHeight-1)];
    [myTableView setBackgroundColor:[UIColor HexStrWithColor:@"dedede"]];
    [myTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [myTableView setScrollEnabled:YES];
    [myTableView setDataSource:self];
    [myTableView setDelegate:self];
    [self.view addSubview:myTableView];
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [currentData count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45.f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *indentifer = @"limit_cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:indentifer];
    if (!cell)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indentifer];
        [cell setBackgroundColor:[UIColor whiteColor]];
        
        UILabel *titleLabel = [[UILabel alloc]init];
        [titleLabel setFont:[UIFont systemFontOfSize:16]];
        [titleLabel setTag:102];
        [cell addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make)
         {
             make.centerY.equalTo(cell);
             make.left.equalTo(cell.mas_left).with.offset(20);
             make.width.equalTo(cell).with.multipliedBy(0.5);
             make.height.equalTo(cell.mas_height);
         }];
    }

        NSDictionary *dic = [currentData objectAtIndex:indexPath.row];
        UILabel *titleLabel= (UILabel *)[cell viewWithTag:102];
        [titleLabel setText:[dic objectForKey:@"name"]];
  
        UIView *boardView = [[UIView alloc]initWithFrame:CGRectMake(0, [self tableView:tableView heightForRowAtIndexPath:indexPath]-1, kUIScreenWidth, 1)];
        [boardView setBackgroundColor:[UIColor HexStrWithColor:@"dedede"]];
        [cell addSubview:boardView];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSDictionary *dic = [currentData objectAtIndex:indexPath.row];
    NSLog(@"%@", [dic objectForKey:@"name"]);
    self.sendProvince([dic objectForKey:@"name"]);
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
